package com.mlethe.android.demo.recyclerview.adapter;

import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;

import com.mlethe.demo.recyclerview.adapter.R;
import com.mlethe.library.recyclerview.adapter.BaseQuickAdapter;
import com.mlethe.library.recyclerview.listener.OnItemClickListener;
import com.mlethe.library.recyclerview.viewholder.ViewHolder;

import java.util.List;

public class RecyclerViewAdapter extends BaseQuickAdapter<Test> {

    @Override
    protected int getLayoutId(Test item, int position) {
        if (position % 2 == 0) {
            return R.layout.item_recycler_view_adapter_text_2;
        }
        return R.layout.item_recycler_view_adapter_text;
    }

    @Override
    protected void convert(@NonNull ViewHolder holder, Test item, int position) {
        holder.setText(R.id.text_view, item.getName());
        holder.setOnItemClickListener(new OnItemClickListener<Test>() {
            @Override
            public void onItemClick(@NonNull View view, Test item, int position) {
                Log.e("yym", "onItemClick: " + position);
                notifyItemChange(position, "select");
            }
        });
    }

    @Override
    protected void convert(@NonNull ViewHolder holder, Test item, int position, @NonNull List<Object> payloads) {
        super.convert(holder, item, position, payloads);
        if (payloads.contains("select")) {
            Log.e("yym", "convert: ");
            holder.setText(R.id.text_view, item.getName());
        }
    }
}
